<div id="sticky_navigation" style="height:30px;border-bottom:4px solid #DFDFDF;">
    <p class="pull-left" style="font-size:16px; line-height:30px;"><strong><?php echo $this->translate('API广告设置'); ?></strong></p>
    <div class="pull-right">
        <a href="http://help.dbshop.net/index.php/API%E5%B9%BF%E5%91%8A%E8%AE%BE%E7%BD%AE" target="_blank" class="btn btn-small btn-info"><i class="icon-info-sign icon-white"></i> <?php echo $this->translate('查看帮助说明'); ?></a>
    </div>
</div>
<table class="table table-hover">
    <thead style="background:#CCC;">
    <tr>
        <th width="35%"><?php echo $this->translate('调用名称'); ?></th>
        <th width="25%"><?php echo $this->translate('调用标记'); ?></th>
        <th width="25%"><?php echo $this->translate('设置状态'); ?></th>
        <th width="15%"><?php echo $this->translate('操作'); ?></th>
    </tr>
    </thead>
    <?php if(is_array($this->ad) and !empty($this->ad)) foreach ($this->ad as $tag_value) { ?>
        <tr>
            <td><?php echo $this->escapeHtml($tag_value['name']); ?></td>
            <td><?php echo $this->escapeHtml($tag_value['code']); ?></td>
            <td>
                <?php
                $setState = (isset($this->ad_array[$tag_value['code']]) and !empty($this->ad_array[$tag_value['code']])) ? true : false;
                echo $setState ? $this->translate('已设置') : $this->translate('未设置');
                ?>
            </td>
            <td>
                <a href="<?php echo $this->url('dbapi/default',array('action'=>'adEdit'), array('query'=>array('code'=>$tag_value['code']))); ?>"><?php echo $this->translate('设置'); ?></a>
                <?php if($setState) { ?>
                    <span>|</span>
                    <a href="javascript:;" onclick="return ad_clear_js(<?php echo $this->ad_array[$tag_value['code']]['dbapi_ad_id']; ?>);"><?php echo $this->translate('清除'); ?></a>
                <?php } ?>
            </td>
        </tr>
        <?php
    }
    ?>
</table>
<script>
    function ad_clear_js(ad_id) {
        if(window.confirm('<?php echo $this->translate('您确实要清除该广告吗？'); ?>')) {
            $.post("<?php echo $this->url('dbapi/default',array('action'=>'adClear')); ?>",{ad_id:ad_id},
                function(data){
                    if(data == 'true') {
                        window.location.href='<?php echo $this->url('dbapi/default', array('action'=>'adIndex')); ?>';
                        return true;
                    } else {
                        alert(data);
                    }
                });
        }
        return false;
    }
</script>